import {SEARCH} from '../api'
export default (state,action)=>{
  state = state || {
    hot:['周杰伦','17岁','罗志祥','华语原创十大金曲','李荣浩','华晨宇'],
    page:{currentNumber:20,currentPage:1,totalNumber:0},
    songList:[]
  };
  switch(action.type){
    case 'INIT':
      return {...state,page:action.page,songList:action.songList};
    default:
      return state;
  }
}

export const getSearchResult = (text) => (dispatch) =>{
  fetch(SEARCH+'/'+text).then(data=>data.json()).then(res=>{
    dispatch({type:'INIT',page:res.data.page,songList:res.data.songList})
  })
}